import pygame, objects

#short init section for pygame
pygame.init()
size = [840, 600]
screen = pygame.display.set_mode(size)
pygame.display.set_caption("DUNGEONBASTARD")

#random variables
done = False
clock = pygame.time.Clock()
keys = set([])
green = [0, 255, 0]
red = [255, 0, 0]
grey = [128, 128, 128]

#INIT THE PLAYER AND ENEMY
player = objects.Player()
enemy = objects.enemy()
player.Location = [200, 200]
enemy.Location = [500, 500]

while done == False:

        clock.tick(60)

        for event in pygame.event.get():
                if event.type == pygame.QUIT:
                        done = True
                if event.type == pygame.KEYDOWN:
                        keys.add(event.key)
                if event.type == pygame.KEYUP:
                        keys.discard(event.key)

        for key in keys:        
                if key == 273:  #Up
                        if player.Location[1] > 0:
                                player.Location = [player.Location[0], player.Location[1] - 5]
                        else:
                                player.Location[1] = 0
                if key == 274:  #Down
                        if player.Location[1] < 550:
                                player.Location = [player.Location[0], player.Location[1] + 5]
                        else:
                                player.Location[1] = 550
                if key == 275:  #Right
                        if player.Location[0] < 790:
                                player.Location = [player.Location[0] + 5, player.Location[1]]
                        else:
                                player.Location[0] = 790
                if key == 276:  #Left
                        if player.Location[0] > 0:
                                player.Location = [player.Location[0] - 5, player.Location[1]]
                        else:
                                player.Location[0] = 0

        if enemy.Location[0] < player.Location[0]:
                enemy.Location = [enemy.Location[0] + 3, enemy.Location[1]]
        elif enemy.Location[0] > player.Location[0]:
                enemy.Location = [enemy.Location[0] - 3, enemy.Location[1]]
        if enemy.Location[1] < player.Location[1]:
                enemy.Location = [enemy.Location[0], enemy.Location[1] + 3]
        elif enemy.Location[1] > player.Location[1]:
                enemy.Location = [enemy.Location[0], enemy.Location[1] - 3]
       
        screen.fill([0,0,0])
        screen.blit(enemy.currentFrame, enemy.Location)
        screen.blit(player.currentFrame, player.Location)
        pygame.display.flip()

pygame.quit() 